package com.xzmzhp.dao.cos.sql;

import com.xzmzhp.utils.StringUtils;
import org.apache.ibatis.jdbc.SQL;

import java.util.Map;

/**
 * @author: 王源(xm)
 * @create: 2022-04-23 22:42
 * @program: ams
 * @description: cos服配件相关sql
 */
public class OrnamentsSql {
    /**
     * 根据条件查询cos服配件相关信息sql
     * @param param 相关参数
     *        cosId cos服id
     *        ornamentsName cos配件名称
     *        ornamentsTypeName cos配件类型名称
     *        ornamentsStatus cos配件状态
     * @return cos配件相关信息sql
     */
    public String findAll(Map<String, Object> param){
        //cos服id
        Integer cosId = Integer.parseInt(param.get("cosId").toString());
        //cos配件名称
        String ornamentsName = param.get("ornamentsName").toString();
        //cos配件类型名称
        String ornamentsTypeName = param.get("ornamentsTypeName").toString();
        //cos配件状态
        Integer ornamentsStatus = Integer.parseInt(param.get("ornamentsStatus").toString());

        return new SQL(){
            {
                SELECT("cos_id,ornaments_id,ornaments_name,ornaments_status,ornaments_type_id,ornaments_type_name");
                FROM("ornaments");
                if (StringUtils.isNotNull(cosId)) {
                    WHERE("ornaments.cos_id = " + cosId);
                }
                if (StringUtils.isNotEmpty(ornamentsName)) {
                    WHERE("ornaments_name = '%" + ornamentsName + "%'");
                }
                if (StringUtils.isNotEmpty(ornamentsTypeName)) {
                    WHERE("ornaments_type_name = '%" + ornamentsTypeName + "%'");
                }
                if (StringUtils.isNotNull(ornamentsStatus)) {
                    WHERE("ornaments_status = " + ornamentsStatus);
                }
                ORDER_BY("ornaments_status");
            }
        }.toString();
    }

    /**
     * 根据条件查询cos服配件相关信息sql
     * @param param 相关参数
     *        cosId cos服id
     *        cosName cos服名称
     *        ornamentsName cos配件名称
     *        ornamentsTypeName cos配件类型名称
     *        ornamentsStatus cos配件状态
     * @return cos配件相关信息sql
     */
    public String ornamentsByParam(Map<String,Object> param){
        //cos服id
        Integer cosId = Integer.parseInt(param.get("cosId").toString());
        //cos服名称
        String cosName = param.get("cosName").toString();
        //cos配件名称
        String ornamentsName = param.get("ornamentsName").toString();
        //cos配件类型名称
        String ornamentsTypeName = param.get("ornamentsTypeName").toString();
        //cos配件状态
        Integer ornamentsStatus = Integer.parseInt(param.get("ornamentsStatus").toString());

        return new SQL(){
            {
                SELECT("cos_id,cos_name,ornaments_id,ornaments_name,ornaments_status,ornaments_type_id,ornaments_type_name");
                FROM("cos,ornaments");
                WHERE("cos.cos_id = ornaments.cos_id");
                if (StringUtils.isNotEmpty(cosName)) {
                    WHERE("cos_name = '%" + cosName + "%'");
                }
                if (StringUtils.isNotNull(cosId)) {
                    WHERE("ornaments.cos_id = " + cosId);
                }
                if (StringUtils.isNotEmpty(ornamentsName)) {
                    WHERE("ornaments_name = '%" + ornamentsName + "%'");
                }
                if (StringUtils.isNotEmpty(ornamentsTypeName)) {
                    WHERE("ornaments_type_name = '%" + ornamentsTypeName + "%'");
                }
                if (StringUtils.isNotNull(ornamentsStatus)) {
                    WHERE("ornaments_status = " + ornamentsStatus);
                }
                ORDER_BY("ornaments_status,cos_name");
            }
        }.toString();
    }
}
